import {localStorage,sessionStorage} from '@/utils/storage';

export function getToken(){
    let token=sessionStorage.get('access_token')||localStorage.get('access_token')
    return token
}

export function getRefreshToken(){
    let refreshToken=sessionStorage.get('refresh_token')||localStorage.get('refresh_token')
    return refreshToken
}

export function setToken(token:string,remember:boolean){
    removeToken()
    if(remember){
        localStorage.set('access_token',token)
    }else{
        sessionStorage.set('access_token',token)
    }
}

export function setTokenPair(accessToken:string, refreshToken:string, remember:boolean){
    removeToken()
    if(remember){
        localStorage.set('access_token',accessToken)
        localStorage.set('refresh_token',refreshToken)
    }else{
        sessionStorage.set('access_token',accessToken)
        sessionStorage.set('refresh_token',refreshToken)
    }
}

export function removeToken(){
    localStorage.remove('access_token')
    sessionStorage.remove('access_token')
    localStorage.remove('refresh_token')
    sessionStorage.remove('refresh_token')
}